package lambda;

import java.util.function.Consumer;

/**
 * 消费者：提供参数，无返回值
 */
public class ConsumerTest {
    public static void main(String[] args) {
        printHello(str -> System.out.println(str.toUpperCase()));
        printHello(str -> System.out.println(str.toUpperCase()), str -> System.out.println(str.toLowerCase()));
    }

    /**
     * 单次消费
     */
    private static void printHello(Consumer<String> consumer) {
        consumer.accept("Hello");
    }

    /**
     * 多次消费
     */
    private static void printHello(Consumer<String> c1, Consumer<String> c2) {
        // 先消费c1再消费c2
        c1.andThen(c2).accept("hello");
    }
}
